package com.swipemaster.record;

import com.swipemaster.R;
import com.swipemaster.common.Const;
import com.swipemaster.common.Global;
import com.swipemaster.network.WorldRecord;

public class ChallengeRecord extends SurvivalRecord
{
	public int lastLevelIndex;
	private static final long serialVersionUID = 1L;

	public ChallengeRecord()
	{
		super(RecordId.CHALLENGE);
	}

	@Override
	public Record clone(WorldRecord worldRecord)
	{
		final ChallengeRecord clone = new ChallengeRecord();
		clone.lastLevelIndex = worldRecord.level;
		clone.time = worldRecord.time;
		return clone;
	}

	@Override
	public String getRecordStringForPHP()
	{
		return lastLevelIndex + "," + time;
	}

	@Override
	public boolean isBetter(Record score)
	{
		final ChallengeRecord other = (ChallengeRecord) score;
		return !score.isValid() || (lastLevelIndex > other.lastLevelIndex)
				|| ((lastLevelIndex == other.lastLevelIndex) && (time < other.time));
	}

	@Override
	public boolean isValid()
	{
		return time > 0;
	}

	@Override
	public String toString()
	{
		return Global.app.getString(R.string.lvl) + " " + (lastLevelIndex + 1) + ", "
				+ Const.decimalFormat.format(time) + "s";
	}
}
